#include "systemc.h"

#define PACMAX 128

SC_MODULE(input){

	sc_in_clk clock;

	sc_in<bool> req;
	sc_out<bool> ack;
	sc_in< sc_lv<8> > data;

	sc_lv<4> interHorizontal;
	sc_lv<4> interVertical;
	sc_lv<8> interNumber;
	sc_lv<8> interData;
	
	int stan;
	void doit(){
		
		while(1){
			if( 1 == req.read() ){
				cout << "@"<< sc_time_stamp() << " INPUT: "<<endl;
				cout << "Stan : " << stan << endl;
				ack.write("1");
				if(stan ==0){
					interHorizontal = data.read().range(7,4);
					interVertical = data.read().range(4,0);
					stan++;
					cout << "interHorizontal : " << interHorizontal << endl;
					cout << "interVertical : " << interVertical << endl;
				}else if(stan== 1){
					interNumber = data.read();
					if(interNumber.to_int() > PACMAX) interNumber = PACMAX;
					stan++;				
					cout << "interNumber : " << interNumber << endl;
				}else if(stan >= 2){
					cout << stan << "+2 " <<interNumber << " "<<interNumber.to_int() << endl;
					
					interData = data.read();
					stan++;
					cout << "data : " << data << endl ;
					if( (stan-2) == interNumber.to_int() ) stan =0;

					
				}
				wait();
				ack.write("0");
				
			}else{// !req

				ack.write("0");

			}
		}
	
	}



	SC_CTOR(input){
		stan =0;
		SC_CTHREAD(doit, clock.pos() );
	}
};

